import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/main_header_list.dart';
import 'package:flutter_eve_plugin/model/health/user_body_property.dart';
import 'package:flutter_eve_plugin/model/health/user_info.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/health/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class MainHeaderStackWidget extends StatelessWidget {
  const MainHeaderStackWidget({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(
        converter: (store) => AppStateViewModel(
            state: store.state,
            healthStateViewModel: HealthStateViewModel(nextClick: () {
              Navigator.pushNamed(context, RouteConstant.WeightDetailsPage);
            })),
        builder: (context, vm) {
          List<UserBodyDataInfo> infoList =
              vm.state.headlthState.userBodyModel.data;
          var weightList = infoList?.where((item) {
            return item.name == '体重';
          })?.toList();
          UserBodyDataInfo bodyInfo;
          if (weightList == null || weightList.isEmpty) {
            bodyInfo = UserBodyDataInfo('', '', '', 0, '', '', 0, 0, 0, 0, '',
                0, 0, 0, '', 0, '', '', '', '', '', null, '', null, '');
          } else {
            bodyInfo = weightList?.first;
          }
          UserInfoModel userInfo = vm.state.accountInfoState.userInfoModel;
          return Stack(
            children: <Widget>[
              buildBgPositioned(vm),
              Positioned(
                left: setRatio(22),
                bottom: setRatio(25),
                child: GestureDetector(
                  onTap: vm.healthStateViewModel.nextClick,
                  child: Container(
                    width: setRatio(84),
                    height: setRatio(23),
                    child: Center(
                      child: Text(
                        '体重:${bodyInfo.value ~/ 1000}kg',
                        style: TextStyle(
                            color: Color(0xFFFFFFFF), fontSize: setTextSp(11)),
                      ),
                    ),
                  ),
                ),
              ),
              Positioned(
                  left: setRatio((357 - 90) / 2),
                  top: setRatio(3),
                  child: Container(
                    width: setRatio(90),
                    height: setRatio(20),
                    child: Center(
                        child: Text(
                      '${userInfo.nickname}的琥珀',
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          color: Color(0xFFFFFFFF), fontSize: setTextSp(13)),
                    )),
                  )),
              Positioned(
                left: setRatio(119),
                top: setRatio(54),
                child: Container(
                    width: setRatio(211),
                    height: setRatio(192),
                    child: MainHeaderListWidget()),
              )
            ],
          );
        });
  }

  Positioned buildBgPositioned(AppStateViewModel vm) {
    if (vm.state.headlthState.propertyHealthModel.illStatus == 0) {
      return Positioned(
        child: Image.asset(
          imageUtilHuPo('health/icon_hupo_health@2x'),
          width: setRatio(93),
          height: setRatio(164),
        ),
        left: setRatio(17),
        top: setRatio(42),
      );
    } else {
      return Positioned(
        child: Image.asset(
          imageUtilHuPo('health/icon_hupo_sick@2x'),
          width: setRatio(93),
          height: setRatio(164),
        ),
        left: setRatio(17),
        top: setRatio(42),
      );
    }
  }
}
